package com.studyv3.test.controller.take;

import com.studyv3.common.core.controller.BaseController;
import com.studyv3.common.core.domain.R;
import com.studyv3.test.domain.vo.ApplyTakeVo;
import com.studyv3.test.domain.vo.ApplyTakeWhere;
import com.studyv3.test.service.ApplyTakeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * lb_领取申请/审批(ApplyTake)表控制层
 *
 * @author makejava
 * @since 2024-05-06 18:47:49
 */
@Api("领用申请")
@RestController
@RequestMapping("/applyTake")
public class ApplyTakeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ApplyTakeService applyTakeService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @ApiOperation("分页查询申请列表")
    @GetMapping("/page")
    public R queryByPage(ApplyTakeWhere applyTakeWhere) {
        return applyTakeService.queryByPage(applyTakeWhere);
    }

    @ApiOperation("分页查询审批页面的申请列表")
    @GetMapping("/pageunpass")
    public R queryByPageUnpass(ApplyTakeWhere applyTakeWhere) {
        return applyTakeService.queryByUnPass(applyTakeWhere);
    }

    /**
     * 通过主键查询单条数据
     *
     * @return 单条数据
     */
    @ApiOperation("通过id查询领用申请")
    @GetMapping("/queryById")
    public R queryById(@RequestBody Map<String,Integer> map) {
        return applyTakeService.queryById(map.get("id"));
    }

    /**
     * 新增数据
     *
     * @param applyTake 实体
     * @return 新增结果
     */
    @ApiOperation("新增领用申请")
    @PostMapping("/add")
    public R add(@RequestBody ApplyTakeVo applyTake) {
        return applyTakeService.insert(applyTake);
    }

    /**
     * 编辑数据
     *
     * @param applyTake 实体
     * @return 编辑结果
     */
    @ApiOperation("编辑领用申请")
    @PostMapping("/update")
    public R edit(@RequestBody ApplyTakeVo applyTake) {
        System.err.println("1111"+applyTake);
        return applyTakeService.update(applyTake);
    }

    @ApiOperation("通过领用申请")
    @PostMapping("/pass")
    public R pass(@RequestBody ApplyTakeVo applyTake) {
        return applyTakeService.pass(applyTake);
    }
    @ApiOperation("批量通过领用申请")
    @PostMapping("/passbatch")
    public R passbatch(Integer[] ids) {
        return applyTakeService.passbatch(ids);
    }
    @ApiOperation("删除领用申请")
    @PostMapping("/del")
    public R deleteById(@RequestBody Map<String,Integer> map) {
        return applyTakeService.deleteById(map.get("id"));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{ids}")
    public R deleteByIds(@PathVariable Integer[] ids) {
        return applyTakeService.deleteByIds(ids);
    }

    @ApiOperation("导入")
    @PostMapping("import")
    public R importExcel(@RequestPart MultipartFile file) throws IOException {
        return applyTakeService.importExcel(file.getInputStream());
    }
    @ApiOperation("导出")
    @PostMapping("export")
    public void exportExcel(HttpServletResponse response, ApplyTakeWhere applyTakeWhere) throws IOException {
        applyTakeWhere.setUserid(getUserId());
        //设置文件下载
        response.setHeader("Content-Disposition","attachment;filename="+System.currentTimeMillis()+"-applyTake.xlsx");
        applyTakeService.exportExcel(response.getOutputStream(), applyTakeWhere);
    }

    @ApiOperation("获取不同状态的申请数量")
    @PostMapping("/getCount")
    public Long getCount(@RequestBody ApplyTakeWhere applyTakeWhere){
        return applyTakeService.getCount(applyTakeWhere);
    }

}

